//
//  oldMessageManager.m
//  laonianbang
//
//  Created by 勇拓 李 on 17/10/29.
//  Copyright © 2017年 zaiyou. All rights reserved.
//

#import "oldMessageManager.h"

@interface oldMessageManager()
@property (nonatomic, assign)oldMessageType nctype;
@end

@implementation oldMessageManager

NSString *GetMessageType(oldMessageType status) {
    switch (status) {
        case orderCreate:
            return @"old_message_create";
        case orderStart:
            return @"old_message_start";
        case orderEnd:
            return @"old_message_end";
        case orderFail:
            return @"old_message_fail";
        case orderReject:
            return @"old_message_reject";
        case orderCancel:
            return @"old_message_cancel";
        case userServerApprovePass:
            return @"old_message_reject";
        case userServerApproveFail:
            return @"old_message_cancel";
        case newMessage:
            return @"old_new_momentmessage";
        case paySuccess:
            return @"pay_success";
        case payFail:
            return @"pay_failed";
        default:
            return @"old_message_all";
    }
}

- (instancetype)initWithType:(oldMessageType)type
{
    self = [super init];
    if (self) {
        self.nctype = type;
    }
    
    return self;
}


- (void)registerForNotifications
{
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
        
    [nc addObserver:self selector:@selector(receiveMessage:)
               name:GetMessageType(_nctype) object:nil];
}

- (void)unregisterFromNotifications
{
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc removeObserver:self name:GetMessageType(_nctype) object:nil];
}

- (void)receiveMessage:(NSNotification *)notice
{
    [self.delegate receiveMessage:notice.object type:_nctype];
}

@end
